package com.ruoyi.project.digital.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.project.digital.domain.dto.PetAnnexDto;
import org.springframework.stereotype.Service;
import com.ruoyi.project.digital.mapper.PetAnnexMapper;
import com.ruoyi.project.digital.domain.PetAnnex;
import com.ruoyi.project.digital.service.IPetAnnexService;
import org.springframework.util.ObjectUtils;

/**
 * 宠物附件Service业务层处理
 *
 * @author ruoyi
 * @date 2023-12-18
 */
@Service
public class PetAnnexServiceImpl extends ServiceImpl<PetAnnexMapper, PetAnnex> implements IPetAnnexService {

    /**
     * 查询宠物附件
     *
     * @param id 宠物附件ID
     * @return 宠物附件
     */
    @Override
    public PetAnnex selectPetAnnexById(Long id) {
        return baseMapper.selectPetAnnexById(id);
    }

    /**
     * 查询宠物附件列表
     *
     * @param petAnnex 宠物附件
     * @return 宠物附件
     */
    @Override
    public List<PetAnnex> selectPetAnnexList(PetAnnex petAnnex) {
        return baseMapper.selectPetAnnexList(petAnnex);
    }

    /**
     * 新增宠物附件
     *
     * @param petAnnex 宠物附件
     * @return 结果
     */
    @Override
    public int insertPetAnnex(PetAnnex petAnnex) {
        List<PetAnnexDto> dtoList = petAnnex.getPetAnnexDtoList();
        if (!ObjectUtils.isEmpty(dtoList)) {
            List<PetAnnex> annexList = new ArrayList<>();
            for (PetAnnexDto dto : dtoList) {
                PetAnnex annex = new PetAnnex();
                annex.setFileName(dto.getFileName());
                annex.setFileUrl(dto.getFileUrl());
                annex.setPetId(petAnnex.getPetId());
                annexList.add(annex);
            }
            return saveBatch(annexList)?1:0;
        }
        return baseMapper.insertPetAnnex(petAnnex);
    }

    /**
     * 修改宠物附件
     *
     * @param petAnnex 宠物附件
     * @return 结果
     */
    @Override
    public int updatePetAnnex(PetAnnex petAnnex) {
        return baseMapper.updatePetAnnex(petAnnex);
    }

    /**
     * 批量删除宠物附件
     *
     * @param ids 需要删除的宠物附件ID
     * @return 结果
     */
    @Override
    public int deletePetAnnexByIds(Long[] ids) {
        return baseMapper.deletePetAnnexByIds(ids);
    }

    /**
     * 删除宠物附件信息
     *
     * @param id 宠物附件ID
     * @return 结果
     */
    @Override
    public int deletePetAnnexById(Long id) {
        return baseMapper.deletePetAnnexById(id);
    }
}
